const Koa = require("koa");
const koaBody = require('koa-body');
const koaStatic = require("koa-static");
const cors = require("koa2-cors");
const fs = require('fs')
const path = require('path')
import { router } from "./middleware/request";
import connectionDatabse from "./server/database";
import { PUBLIC_PATCH, PORT } from "./config";

const app = new Koa();
// 连接数据库
const db = connectionDatabse();

// 接口文件
import "./api/controllers/uploadFile";
import "./api/controllers/Carousel";
import "./api/controllers/Orders";
import "./api/controllers/Category";
import "./api/controllers/Product";


app.use(koaStatic(__dirname));
app.use(koaBody({
    multipart: true, formidable: {
        maxFileSize: 200 * 1024 * 1024
    }
}));
app.use(cors());
app.use(router.routes())
const server = app.listen(PORT || 3000, () => {
    console.log(`服务器启动成功：http://127.0.0.1:${PORT}`);
});
export default app;

